/**
 * @file 轨迹数据相关API接口
 * @description 定义与轨迹数据相关的API接口
 * @date 2024-03-28
 */

import { request } from '@/utils/http/request';
import type { TrackData as Track, TrackQueryParams, DeviceQueryParams, DeviceListResponse } from '@/types/track';
import type { ApiResponse } from '@/types';

/**
 * 获取轨迹列表
 * @returns 轨迹列表
 */
export function getTrackList(): Promise<ApiResponse<Track[]>> {
  return request<Track[]>({
    url: '/api/track/list',
    method: 'GET'
  });
}

/**
 * 根据ID获取轨迹详情
 * @param id 轨迹ID
 * @returns 轨迹详情
 */
export function getTrackById(id: string): Promise<ApiResponse<Track>> {
  return request<Track>({
    url: `/api/track/${id}`,
    method: 'GET'
  });
}

/**
 * 保存轨迹
 * @param track 轨迹数据
 * @returns 保存结果
 */
export function saveTrack(track: Track): Promise<ApiResponse<Track>> {
  return request<Track>({
    url: '/api/track/save',
    method: 'POST',
    data: track
  });
}

/**
 * 获取设备轨迹数据
 * @param params 查询参数
 * @returns 轨迹数据
 */
export function getTrackData(params: TrackQueryParams): Promise<ApiResponse<Track>> {
  return request<Track>({
    url: `/api/track/${params.deviceId}`,
    method: 'GET',
    params: {
      startTime: params.startTime,
      endTime: params.endTime
    }
  });
}

/**
 * 删除轨迹
 * @param id 轨迹ID
 * @returns 删除结果
 */
export function deleteTrack(id: string): Promise<ApiResponse<boolean>> {
  return request<boolean>({
    url: `/api/track/${id}`,
    method: 'DELETE'
  });
}

/**
 * 获取所有设备列表
 * @param params 查询参数
 * @returns 设备ID列表
 */
export function getAllDevices(params?: DeviceQueryParams): Promise<ApiResponse<DeviceListResponse>> {
  return request<DeviceListResponse>({
    url: '/api/track/device/list',
    method: 'GET',
    params
  });
} 